<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@include file="/common/common.jspf"%>
<link href="${ctx}/css/switcher.css" rel="stylesheet">
<script type="text/javascript" src="${ctx}/js/system/user/add.js"></script><style type="text/css">
.col-sm-3 {
    position: relative;
    top: 8px;
	width: 20%;
	float: left;
	text-align: right;
}

.col-sm-9 {
	width: 50%;
	float: left;
	text-align: left;
}


label[class^="btn btn-default"] {
	margin-top: -4px;
}
</style>

</head>
<body>
	<div class="l_err" style="width: 100%; margin-top: 2px;"></div>
	<form id="form" name="form" class="form-horizontal" method="post"
		action="${ctx}/mq/addMq.shtml">
		<input type="hidden" class="form-control checkacc" value="${mq.id}"
			   name="materialQualityForMap.id" id="id">
		<section class="panel panel-default">
			<div class="panel-body">
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">来料质检编号</label>
				<div class="col-sm-9">
					<input type="text" class="form-control checkabh"
						   placeholder="" name="materialQualityForMap.detection_code" id="detection_code" readonly = "readonly">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">物料名称</label>
				<div class="col-sm-9">
					<input type="text" class="form-control checkName"  readonly = "readonly"
						   placeholder="" name="materialQualityForMap.material_code" id="material_code" >
					<span class="input-group-btn">
						<button class="btn btn-info" type="button"
								style="height: 34px; position: absolute; top: -35px; left: 338px;"
								onclick="getItemMain('material_code','name');">
							<span class="glyphicon glyphicon-search"></span>
						</button>
					</span>
				</div>
			</div>
			<%--<div class="form-group">--%>
				<%--<label class="col-sm-3 control-label">检验项目</label>--%>
				<%--<div class="col-sm-9">--%>
					<%--<div class="input-group">--%>
						<%--<input type="text" class="form-control" placeholder="" readonly = "readonly"--%>
							   <%--name="materialQualityForMap.detection_project" id="detection_project">--%>
						<%--<span class="input-group-btn">--%>
						<%--<button class="btn btn-info" id="workorder" type="button"--%>
								<%--style="height: 34px;"--%>
								<%--onclick="getDetection();">--%>
							<%--<span class="glyphicon glyphicon-search"></span>--%>
						<%--</button>--%>
					<%--</span>--%>
					<%--</div>--%>
				<%--</div>--%>
			<%--</div>--%>

			<div class="form-group">
				<label class="col-sm-3 control-label">抽检数</label>
				<div class="col-sm-9">
					<input type="text" class="form-control"
						   name="materialQualityForMap.sampling"
						   id="sampling">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">不合格数</label>
				<div class="col-sm-9">
					<input type="text" class="form-control checkName"
						   placeholder="" name="materialQualityForMap.unqalified" id="unqalified">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">合格率</label>
				<div class="col-sm-9">
					<input type="text" class="form-control checkName"
						   placeholder="" name="materialQualityForMap.percent_pass" id="percent_pass" readonly = "readonly">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">检验时间</label>
				<div class="col-sm-9">
					<input type="date" class="form-control"
						   name="materialQualityForMap.detection_time"
						   id="detection_time">
				</div>
			</div>


			<div class="form-group">
				<label class="col-sm-3 control-label">检验人</label>
				<div class="col-sm-9">
					<input type="text" class="form-control checkName"
						   placeholder="" name="materialQualityForMap.surveyor" id="surveyor">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">检验结果</label>
				<div class="col-sm-9">
					<select class="form-control" name="materialQualityForMap.the_result" id="the_result" >
						<option value="0">通过</option>
						<option value="1">未通过</option>
					</select>
				</div>
			</div>

			</div>
			<footer class="panel-footer text-right bg-light lter">
				<button type="submit" class="btn btn-success btn-s-xs">提交</button>
			</footer>
		</section>
	</form>
	<input type="hidden" value="none" id="no">
	<template id="theTemplate">
		<tr id="myfirst">
			<td  id="{contentid}">{id}</td>
			<td>{content}</td>
			<td>测试</td>
			<td><input style= "background-color:transparent;border:0;width: 56px" placeholder="输入记录" id="{record}"></td>
			<td><input style= "background-color:transparent;border:0;width: 85px" placeholder="输入不合格量" id="{no_number}"></td>
			<th rowspan="100" style="text-align: center; vertical-align: middle;" ><input  style= "background-color:transparent;border:0;width: 50px" placeholder="合格量" id="qualified"></th>
			<th rowspan="100" style="text-align: center; vertical-align: middle;"><div class="form-check form-check-inline">
				<input class="form-check-input" type="checkbox" id="inlineCheckbox1" value="option1">
			</div>
			</th>
		</tr>
	</template>

	<template id="towtemp">

		<tr id="mytow">
			<td id="{contentid}">{id}</td>
			<td>{content}</td>
			<td>测试</td>
			<td><input style= "background-color:transparent;border:0;width: 56px" placeholder="输入记录" id="{record}"></td>
			<td><input style= "background-color:transparent;border:0;width: 85px" placeholder="输入不合格量" id="{no_number}"></td>
		</tr>

	</template>

	<table id="table_Id"  class="bTable table table-striped table-bordered table-hover table-condensed">
		<thead>
		<tr>
			<th>id</th>
			<th>检验内容</th>
			<th>检验标准</th>
			<th>检验记录</th>
			<th>不合格数量</th>
			<th>合格数量</th>
			<th>结果判定</th>
		</tr>
		</thead>
		<tbody id="addBody">
		</tbody>
	</table>

	<script type="text/javascript">
		onloadurl();
	</script>
	<script type="text/javascript"
		src="${ctx}/notebook/notebook_files/bootstrap-filestyle.min.js"></script>
<script src="${ctx}/js/public/jquery.switcher.js"></script>
<script type="text/javascript">

	//检测数据input数据状态
	$("#unqalified").bind("input propertychange",function(event){
		//获取sampling 数据
		var sa = $("#sampling").val();
		//判断sa是否有数据
		if(sa==''||sa==undefined||sa==null ){
			return;
		}
		var num = parseInt(sa);
		var num2 = parseInt($("#unqalified").val());
		$("#percent_pass").val((100 - (Math.round(num2 / num * 10000) / 100)) + "%");
	});

	//插入数据
	function inser_data(data) {
		var name =  $("#detection_project").val();
		if(name==''||name==undefined||name==null ){
			$("#detection_project").val(data);
		}else {
			$("#detection_project").val(name +","+ data);
		}

	}

	function getDetection() {
		layer.open({
			title : "检测项目信息列表",
			type : 2,
			area : [ "80%", "80%" ],
			content : rootPath + '/base/getDetection.shtml'
		});
	}
	//自动生成id
	//
	$(document).ready(function(){
		var myDate = getNowFormatDate();
		$("#detection_code").val("MQ"+ myDate + getRandomInt(100,1000));
	});


	function getNowFormatDate() {
		var date = new Date();
		var seperator1 = "-";
		var seperator2 = ":";
		var year = date.getFullYear();
		var month = date.getMonth() + 1;
		var strDate = date.getDate();
		if (month >= 1 && month <= 9) {
			month = "0" + month;
		}
		if (strDate >= 0 && strDate <= 9) {
			strDate = "0" + strDate;
		}
		//OF2022-02-12 13:52:30
		var currentdate = year + seperator1 + month + seperator1 + strDate
				+ date.getHours() + seperator2 + date.getMinutes()
				+ seperator2 + date.getSeconds();
        currentdate= currentdate.replaceAll("-","");
        currentdate= currentdate.replaceAll(":","");
		return currentdate;
	}

    function getRandomInt(min, max) {
        min = Math.ceil(min);
        max = Math.floor(max);
        return Math.floor(Math.random() * (max - min)) + min; //不含最大值，含最小值
    }
	var temp_number = 0;
	function selectData(data) {
		//根据id带出关联数据
		var mynumber = data.id;
		$.ajax({
			type: 'GET',
			url: 'getRelevanceData.shtml',
			data: {"id":data.id},
			dataType:'JSON',
			success:function(data){
				var d = JSON.parse(data);
				$.each(d,function (i,v) {
					if($("#no").val() == "none"){
						var template = $("#theTemplate").html();
						template = template.replaceAll("{contentid}",temp_number);
						template = template.replaceAll("{id}",mynumber);
						template = template.replaceAll("{content}",v.ly_content);
						template = template.replaceAll("{record}","record"+ temp_number);
						template = template.replaceAll("{no_number}","no_number"+ temp_number);
						temp_number = temp_number + 1;
						$("#addBody").append(template);
						$.switcher();
						$("#no").val("yes");
					}else {
						var template = $("#towtemp").html();
						template = template.replaceAll("{contentid}",temp_number);
						template = template.replaceAll("{id}",mynumber);
						template = template.replaceAll("{content}",v.ly_content);
						template = template.replaceAll("{record}","record"+ temp_number);
						template = template.replaceAll("{no_number}","no_number"+ temp_number);
						temp_number = temp_number + 1;
						$("#addBody").append(template);
					}

				})
			}
		});
	}



</script>
</body>
</html>